package chapter02;

public class Euclid {

    public static void main(String[] args) {
        long gcd = gcd(10234324, 524543434);
        System.out.println(gcd);

        long pow = pow(10, 10);
        System.out.println(pow);

        Math.pow(10, 10);
    }

    public static long gcd(long m, long n) {
        while (n != 0) {
            long rem = m % n;
            m = n;
            n = rem;
        }
        return m;
    }

    public static long pow(long x, int n) {
        if (n == 0) {
            return 1;
        }
        if (n == 1) {
            return x;
        }
        if (isEven(n)) {
            return pow(x * x, n / 2);
        }else {
            return pow(x * x, n / 2) * x;
        }
    }

    private static boolean isEven(int n) {
        return n % 2 == 0;
    }
}
